<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace S3\Sample3Bundle\Twig\Extensions;

use Symfony\Component\DependencyInjection\ContainerInterface;
use \Twig_Extension;
/**
 * Description of CommonExtension
 *
 * @author minh.ton
 */
class CommonExtension extends \Twig_Extension{
    protected $container;
    
    public function __construct(ContainerInterface $container) {
        $this->container = $container;
    }
    
    public function getFunctions()
    {
        return array(            
            'custom_string' => new \Twig_Function_Method($this, 'getSampleString'),
        );
    }
    
    public function getName(){
        return 'common_twig_extension';
    }    
    
    /**
     * Create a simple function
     * @return string
     */
    public function getSampleString($param)
    {
        return 'param:'.$param;
    }
    
    /**
     * How to create a custom filter
     * @return type
     */
    public function getFilters() {
        //parent::getFilters();
        return array(
            'price' => new \Twig_Filter_Method($this, 'priceFilter')
        );
    }
    
    public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandSep = ',')
    {
        $price = number_format($number, $decimals, $decPoint, $thousandSep);
        $price = '$'. $price;
        return $price;
    }
}